home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / scsiDiskBoot / devSCSI.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-13  |  4.4 KB  |  165 lines

  1. /* 
  2.  * devSCSI.c --
  3.  *
  4.  *    SCSI = Small Computer System Interface. The routines in this file
  5.  *    are indented to aid in formatting SCSI command blocks.
  6.  *
  7.  * Copyright 1986 Regents of the University of California
  8.  * All rights reserved.
  9.  * Permission to use, copy, modify, and distribute this
  10.  * software and its documentation for any purpose and without
  11.  * fee is hereby granted, provided that the above copyright
  12.  * notice appear in all copies.  The University of California
  13.  * makes no representations about the suitability of this
  14.  * software for any purpose.  It is provided "as is" without
  15.  * express or implied warranty.
  16.  */
  17.  
  18. #ifdef notdef
  19. static char rcsid[] = "$Header: /sprite/src/kernel/dev/RCS/devSCSI.c,v 8.8 89/05/23 10:02:18 mendel Exp Locker: mendel $ SPRITE (Berkeley)";
  20. #endif not lint
  21.  
  22.  
  23. #include "sprite.h"
  24. #include "mach.h"
  25. #include "dev.h"
  26. #include "devInt.h"
  27. #include "scsi.h"
  28. #include "scsiDevice.h"
  29. #include "dbg.h"
  30. #include "vm.h"
  31. #include "sys.h"
  32. #include "sync.h"
  33. #include "fs.h"
  34. #include "stdlib.h"
  35. #include "sched.h"
  36.  
  37.  
  38. /*
  39.  *----------------------------------------------------------------------
  40.  *
  41.  * DevScsiMapSense --
  42.  *
  43.  *    Map a SCSI Class7 Sense data structure into a Sprite ReturnStatus
  44.  *    and a printable error string.
  45.  *
  46.  * Results:
  47.  *    TRUE if the mapping succeeded. FALSE if the argument is not 
  48.  *    Class7 sense data.
  49.  *
  50.  * Side effects:
  51.  *    None.
  52.  *
  53.  *----------------------------------------------------------------------
  54.  */
  55. Boolean
  56. DevScsiMapClass7Sense(senseLength,senseDataPtr,statusPtr,errorString)
  57.     int        senseLength;    /* Length of the sense data at senseDataPtr. */
  58.     char    *senseDataPtr;    /* The sense data. */
  59.     ReturnStatus *statusPtr;    /* OUT - The Sprite ReturnStatus. */
  60.     char    *errorString;    /* OUT - A buffer to write a printable string
  61.                  * describing the data. Must be at least 
  62.                  * MAX_SCSI_ERROR_STRING in length. */
  63. {
  64.     register ScsiClass7Sense    *sensePtr = (ScsiClass7Sense *) senseDataPtr;
  65.     ReturnStatus    status;
  66.  
  67.     /*
  68.      * Default to no error string. 
  69.      */
  70.     *errorString = 0;
  71.  
  72.     if (senseLength < sizeof(ScsiClass7Sense)) {
  73.     return (FALSE);
  74.     }
  75.     if (sensePtr->error7 != 0x70) {
  76.     return (FALSE);
  77.     }
  78.  
  79.     switch (sensePtr->key) {
  80.     case SCSI_CLASS7_NO_SENSE:
  81.         status = SUCCESS;
  82.         break;
  83.     case SCSI_CLASS7_RECOVERABLE:
  84.         /*
  85.          * The drive recovered from an error.
  86.         status = SUCCESS;
  87.         break;
  88.     case SCSI_CLASS7_NOT_READY:
  89.         status = DEV_OFFLINE;
  90.         break;
  91.     case SCSI_CLASS7_MEDIA_ERROR:
  92.     case SCSI_CLASS7_HARDWARE_ERROR:
  93.         status = DEV_HARD_ERROR;
  94.         break;
  95.     case SCSI_CLASS7_ILLEGAL_REQUEST:
  96.         /*
  97.          * Probably a programming error.
  98.          */
  99.         status = DEV_INVALID_ARG;
  100.         break;
  101.     case SCSI_CLASS7_UNIT_ATTN:
  102.         /*
  103.          * This is an error that occurs after the drive is reset.
  104.          * It can probably be ignored.
  105.          */
  106.         status = SUCCESS;
  107.         break;
  108.     case SCSI_CLASS7_WRITE_PROTECT:
  109.         status = FS_NO_ACCESS;
  110.         break;
  111.     case SCSI_CLASS7_BLANK_CHECK:
  112.         status = DEV_HARD_ERROR;
  113.         break;
  114.     case SCSI_CLASS7_VENDOR:
  115.     case SCSI_CLASS7_ABORT:
  116.     case SCSI_CLASS7_EQUAL:
  117.     case SCSI_CLASS7_OVERFLOW:
  118.         status = DEV_HARD_ERROR;
  119.         break;
  120.     default: {
  121.         status = DEV_HARD_ERROR;
  122.         break;
  123.     }
  124.     }
  125.     *statusPtr = status;
  126.     return TRUE;
  127. }
  128.  
  129. /*
  130.  *----------------------------------------------------------------------
  131.  *
  132.  * DevScsiGroup0Cmd --
  133.  *
  134.  *      Setup a ScsiCmd block for a SCSI Group0 command.
  135.  *
  136.  * Results:
  137.  *    None.
  138.  *
  139.  * Side effects:
  140.  *    Set the various fields in the control block.
  141.  *
  142.  *----------------------------------------------------------------------
  143.  */
  144. void
  145. DevScsiGroup0Cmd(devPtr, cmd, blockNumber,countNumber,scsiCmdPtr)
  146.     ScsiDevice    *devPtr; /* SCSI device target for this command. */
  147.     int        cmd;     /* Group0 scsi command. */
  148.     unsigned int blockNumber;    /* The starting block number for the transfer */
  149.     unsigned int countNumber;    /* Number of sectors (or bytes!) to transfer */
  150.     register ScsiCmd    *scsiCmdPtr; /* Scsi command block to be filled in. */
  151. {
  152.     register  ScsiGroup0Cmd    *c;
  153.  
  154.      bzero((char *)scsiCmdPtr, sizeof(ScsiCmd));
  155.     scsiCmdPtr->commandBlockLen = sizeof(ScsiGroup0Cmd);
  156.     c = (ScsiGroup0Cmd *) scsiCmdPtr->commandBlock;
  157.     c->command = cmd;
  158.     c->unitNumber = devPtr->LUN;
  159.     c->highAddr = (blockNumber & 0x1f0000) >> 16;
  160.     c->midAddr =  (blockNumber & 0x00ff00) >> 8;
  161.     c->lowAddr =  (blockNumber & 0x0000ff);
  162.     c->blockCount =  countNumber;
  163. }
  164.  
  165.